﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService

Partial Class Control_Scholarship_Edit
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            If Not Request.QueryString("Id").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Id")
                ShowData()
            End If
            'xu ly jquery khi post back
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "jqueryEnable", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "jqueryEnable", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If
        End If

    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As Feedback = (From q In data.Feedbacks Where q.ID = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                txtFullName.Text = IIf(IsNothing(p.FullName) = True, "", p.FullName)
                txtDetail.Text = IIf(IsNothing(p.Content) = True, "", p.Content)
                txEmail.Text = IIf(IsNothing(p.Email) = True, "", p.Email)
                txtTitle.Text = IIf(IsNothing(p.Title) = True, "", p.Title)
                txtPhone.Text = IIf(IsNothing(p.Phone) = True, "", p.Phone)
                txtAddress.Text = IIf(IsNothing(p.Address) = True, "", p.Address)

            End If
        End Using
    End Sub
#End Region
#Region "Event for control"
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Using data As New VSEntities
            Dim p As Feedback = (From q In data.Feedbacks Where q.ID = hidID.Value).SingleOrDefault
            Try
                Dim strLogFullName As String = txtFullName.Text.Trim()
                p.Id = hidID.Value
                p.FullName = txtFullName.Text.Trim()
                p.Email = txEmail.Text.Trim
                p.Phone = txtPhone.Text.Trim()
                p.Address = txtAddress.Text.Trim()
                p.Title = txtTitle.Text.Trim()
                p.Content = txtDetail.Text.Trim()
                p.Modified = Date.Now
                p.Modifier = Session("Username")
                data.SaveChanges()
                Insert_App_Log("Edit Feedback:" & strLogFullName.Trim & "", Function_Name.Feedback, Audit_Type.Edit, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                Excute_Javascript("Alertbox('Cập nhật dữ liệu thành công.');window.location ='../../Page/Feedback/List.aspx';", Me.Page, True)
            Catch ex As Exception
                log4net.Config.XmlConfigurator.Configure()
                log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
                Excute_Javascript("Alertbox('Cập nhật thất bại.');", Me.Page, True)
            End Try
        End Using
    End Sub
    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("List.aspx")
    End Sub
    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnBack.Click
        Response.Redirect("List.aspx")
    End Sub

#End Region

    
End Class
